﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace shop.Areas.admin.Controllers
{
    [Authorize]
    public class gioithieuController : Controller
    {
        private LongHAEntities db = new LongHAEntities();

        //
        // GET: /admin/gioithieu/

        public ActionResult Index()
        {
            return View(db.GioiThieux.ToList());
        }

        //
        // GET: /admin/gioithieu/Details/5

        public ActionResult Details(int id = 0)
        {
            GioiThieu gioithieu = db.GioiThieux.Find(id);
            if (gioithieu == null)
            {
                return HttpNotFound();
            }
            return View(gioithieu);
        }

        //
        // GET: /admin/gioithieu/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /admin/gioithieu/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        [ValidateInput(false)]
        public ActionResult Create(GioiThieu gioithieu)
        {
            if (ModelState.IsValid)
            {
                db.GioiThieux.Add(gioithieu);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(gioithieu);
        }

        //
        // GET: /admin/gioithieu/Edit/5

        public ActionResult Edit(int id = 0)
        {
            GioiThieu gioithieu = db.GioiThieux.Find(id);
            if (gioithieu == null)
            {
                return HttpNotFound();
            }
            return View(gioithieu);
        }

        //
        // POST: /admin/gioithieu/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        [ValidateInput(false)]
        public ActionResult Edit(GioiThieu gioithieu)
        {
            if (ModelState.IsValid)
            {
                db.Entry(gioithieu).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(gioithieu);
        }

        //
        // GET: /admin/gioithieu/Delete/5

        //public ActionResult Delete(int id = 0)
        //{
        //    GioiThieu gioithieu = db.GioiThieux.Find(id);
        //    if (gioithieu == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(gioithieu);
        //}

        //
        // POST: /admin/gioithieu/Delete/5

        [HttpPost, ActionName("Delete")]
       // [ValidateAntiForgeryToken]
        public ActionResult Delete(int id)
        {

            GioiThieu gioithieu = db.GioiThieux.Find(id);
            try
            {
                db.GioiThieux.Remove(gioithieu);
                db.SaveChanges();
                
                return Content(Boolean.TrueString);
            }
            catch
            {
                return Content(Boolean.FalseString);
            }
            
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}